import java.util.Scanner;

public class b4 {
    public static void main(String[] args) {
        System.out.println("请输入行数");
        Scanner sc = new Scanner(System.in);
        if (sc.hasNextInt()) {
            int rownum = sc.nextInt();
            printHollowSquare(rownum);
        } else {
            System.out.println("请输入大于1的正整数");
        }
    }

    private static void printHollowSquare(int rownum) {
        if (rownum > 1) {
            for (int i = 1; i <= rownum; i++) {
                for (int j = 1; j <= rownum; j++) {
                    if (i == 1 || i == rownum) {
                        System.out.print("*");
                    } else {
                        if (j == 1 || j == rownum) {
                            System.out.print("*");
                        } else {
                            System.out.print(" ");
                        }
                    }
                }
                System.out.println();
            }
        } else {
            System.out.println("数字应大于1");
        }
    }
}
